<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Column as Col;
use addons\BuilderPlus\components\Edit;
use addons\BuilderPlus\components\Search;
use addons\BuilderPlus\facade\Table;

class Level extends Base
{

    public function getOptions(): array
    {
        return [
            'pk'    => 'id',
            'model' => \app\common\model\Level::class
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->setCheckbox(false)
            ->addColumns([
                ['id', '级别ID', fn(Col $col) => $col->width(80)],
                ['title', '级别名称', null, fn(Edit $e) => $e->require()],
                ['zt_count', '直推人数', null, fn(Edit $e) => $e->number()->require()],
                ['team_count', '团队人数', null, fn(Edit $e) => $e->number()->require()],
                ['indirect', '直推奖', fn(Col $col) => $col->fastRatio(), fn(Edit $e) => $e->ratio()->require()],
                ['flat_tp', '平级奖', fn(Col $col) => $col->fastRatio(), fn(Edit $e) => $e->ratio()->require()],
                ['update_time', '最新修改时间', fn(Col $col) => $col->minWidth(140)]
            ])
            ->addRightButtons(['edit'], 90)
            ->addSearch([
                ['title', '等级名称搜索', fn(Search $search) => $search->condition('Like')]
            ])
            ->fetch();
    }

}
